//
//  TwitterForDetail.m
//  PetApp
//
//  Created by dllo on 16/3/14.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "TwitterForDetail.h"

@interface TwitterForDetail ()

@property (nonatomic, retain) UITextView *textView;

@end

@implementation TwitterForDetail

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.9462 green:0.9416 blue:0.9508 alpha:1.0];
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setTitle:@"保存" forState:UIControlStateNormal];
    [rightButton setTitleColor:[UIColor brownColor] forState:UIControlStateNormal];
    rightButton.frame = CGRectMake(0, 0, 50, 50);
    [rightButton addTarget:self action:@selector(handleAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    
    [self createSubViews];
    
}

- (void)handleAction {
    self.block(self.textView.text);
    [self.navigationController popViewControllerAnimated:YES];

}

- (void)createSubViews {
    
    self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, 100)];
    [self.view addSubview:_textView];
    [_textView release];
    self.textView.backgroundColor = [UIColor whiteColor];
    self.textView.font = [UIFont systemFontOfSize:18];
    self.textView.text = self.textContent;
    [[NSNotificationCenter defaultCenter] addObserverForName:UITextViewTextDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
        NSInteger number = [((UITextView *)[note object]).text length];
        if (number > 50) {
            self.textView.text = [self.textView.text substringToIndex:50];
            number = 50;
            
        }
    }];

    
    
    UILabel *labelOfTip = [[UILabel alloc] initWithFrame:CGRectMake(10, 150, self.view.frame.size.width, 30)];
    [self.view addSubview:labelOfTip];
    [labelOfTip release];
    labelOfTip.text = @"格式: 个性签名限制在50个汉字内";
    labelOfTip.textColor = [UIColor grayColor];
    labelOfTip.font = [UIFont systemFontOfSize:15];
}

- (void)textViewDidChange:(UITextView *)textView {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
